package com.example.aircraftticketingsystemserver.controller;

import com.example.aircraftticketingsystemserver.entity.Passenger;
import com.example.aircraftticketingsystemserver.service.IUserPassengerService;
import com.example.aircraftticketingsystemserver.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lxz
 * @since 2024-08-19
 */
@RestController
@CrossOrigin(origins = {"*","null"})
@RequestMapping("/userPassenger")
public class UserPassengerController {
    @Resource
    private IUserPassengerService userPassengerService;
    @GetMapping("/getPassengersByUserId")
    public Result getPassengersByUserId(@RequestParam(value = "pageNo") Integer pageNo,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "userId")Integer userId,
                                        String passengerName,
                                        String passengerPhone,
                                        String passengerNumber) {
        return Result.ok(userPassengerService.getPassengersByUserId(pageNo,pageSize,userId,passengerNumber,passengerName,passengerPhone));
    }

    /**
     * 根据用户Id查询对应的乘客
     */
    @GetMapping("/getPassengerList")
    public Result getPassengerList(@RequestParam("userId") Integer userId){
        List<Passenger> passengerList = userPassengerService.getPassengerList(userId);
        return Result.ok(passengerList);
    }
    @GetMapping("/getPassengerByParams")
    public Result getPassengerByParams(@RequestParam("userId")Integer userId,
                                       String passengerNumber,
                                       String passengerName,
                                       String passengerPhone){
        List<Passenger> passengerByParams = userPassengerService.getPassengerByParams(userId, passengerNumber, passengerName, passengerPhone);
        return Result.ok(passengerByParams);
    }
}
